

** plot the effect of the shock on returns over years since first sale - also no. of obs since first sale!

local file_path_in "/tochange/"

set more off

insheet  using "`file_path_in'/reg output/annual_return3_clustfipsmain09yearfe09loghpZIL_fipsfips_return.csv", comma clear

keep v1 v7
drop in 1/3

rename v7 beta
rename v1 year
drop if beta=="Yes" | beta=="" | strpos(beta,"(")>0 | beta=="No"
drop if year == "Ln Assets" | year == "$ R^2 $"

replace beta = subinstr(beta,"*","",.)
destring beta, replace

g y = _n-1

summ beta if y == 0
local base0 = `r(mean)'

g beta1 = .
forval i = 1/6 {
	replace beta1 = beta + `base0' if y == `i'
}

keep y beta1
drop if y==0

rename y year3

save "`file_path_in'/reg output/annual_return_coeff_estimates.dta",  replace

insheet using "`file_path_in'/reg output/annual_return_obs_year.csv", comma clear

merge m:1 year3 using "`file_path_in'/reg output/annual_return_coeff_estimates.dta", nogen

label var nhomes_annual "No. Obs"
label var year3  "Years Since First Sale"
label var beta1 "Effect of Shock on Returns"

twoway  bar nhomes_annual year3, sort yaxis(2) yscale(range(0) axis(2)) fcolor(white) lcolor(dkblue)  || connected beta1 year3  , yaxis(1) yscale(range(0) axis(1))   ,  legend(order(1 2))  legend(label(1 "N") label(2 "Performance of Distressed Homes")) graphregion(color(white)) 
graph export "`file_path_in'/reg output/persistance_resale.png", replace
